package com.hzncc.scaffold.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.hzncc.scaffold.entity.Bo.MyReplyBo;
import com.hzncc.scaffold.entity.Bo.ReplyBo;
import com.hzncc.scaffold.entity.Other.Reply;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * <p>
 * 回复表 Mapper 接口
 * </p>
 *
 * @author DrunkBear
 * @since 2022-04-27
 */
@Component
public interface ReplyMapper extends BaseMapper<Reply> {

    @Select("SELECT\n" +
            "\t`reply`.`id`,\n" +
            "\t`reply`.`createTime`,\n" +
            "\t`reply`.`content`,\n" +
            "\t`reply`.`status`,\n" +
            "\t`reply`.`pubTime`,\n" +
            "\t`creator`.`id` AS `creatorId`,\n" +
            "\t`creator`.`name` AS `creatorName`,\n" +
            "\t`creator`.`role` AS `creatorRole`,\n" +
            "\t`creator`.`account` AS `creatorAccount`,\n" +
            "\t`creator`.`telephone` AS `creatorTelephone`,\n" +
            "\t`creator`.`realname` AS `creatorRealname`,\n" +
            "\t`creator`.`instituteName` AS `creatorInstituteName`,\n" +
            "\t`publisher`.`id` AS `publisherId`,\n" +
            "\t`publisher`.`name` AS `publisherName`,\n" +
            "\t`ask`.`id` AS `askId`,\n" +
            "\t`ask`.`title` AS `askTitle`,\n" +
            "\t`ask`.`content` AS `askContent`,\n" +
            "\t`ask->course`.`id` AS `askCourseId`,\n" +
            "\t`ask->course`.`title` AS `askCourseTitle` \n" +
            "FROM\n" +
            "\t`reply` AS `reply`\n" +
            "\tLEFT OUTER JOIN `user` AS `creator` ON `reply`.`userId` = `creator`.`id`\n" +
            "\tLEFT OUTER JOIN `user` AS `publisher` ON `reply`.`publisherId` = `publisher`.`id`\n" +
            "\tINNER JOIN `ask` AS `ask` ON `reply`.`askId` = `ask`.`id`\n" +
            "\tLEFT OUTER JOIN `course` AS `ask->course` ON `ask`.`courseId` = `ask->course`.`id` \n ${ew.customSqlSegment}" +
            "ORDER BY\n" +
            "\t`reply`.`createTime` DESC,\n" +
            "\t`reply`.`id` DESC ")
    public List<ReplyBo> list(@Param(Constants.WRAPPER) QueryWrapper queryWrapper);


    @Select("SELECT\n" +
            "\t`reply`.`id`,\n" +
            "\t`reply`.`createTime`,\n" +
            "\t`reply`.`status`,\n" +
            "\t`reply`.`content`,\n" +
            "\t`ask`.`id` AS `askId`,\n" +
            "\t`ask`.`title` AS `askTitle`,\n" +
            "\t`ask`.`userId` AS `askUserId`,\n" +
            "\t`ask`.`content` AS `askContent`,\n" +
            "\t`ask`.`courseId` AS `askCourseId`,\n" +
            "\t`ask`.`status` AS `askStatus`,\n" +
            "\t`ask`.`tag` AS `askTag`,\n" +
            "\t`ask`.`publisherId` AS `askPublisherId`,\n" +
            "\t`ask`.`pubTime` AS `askPubTime`,\n" +
            "\t`ask`.`createTime` AS `askCreateTime`,\n" +
            "\t`ask`.`scannedNum` AS `askScannedNum`,\n" +
            "\t`ask`.`replyNum` AS `askReplyNum`,\n" +
            "\t`ask`.`lastReplyTime` AS `askLastReplyTime`,\n" +
            "\t`ask->course`.`title` AS `askCourseTitle`,\n" +
            "\t`ask->creator`.`id` AS `askCreatorId`,\n" +
            "\t`ask->creator`.`name` AS `askCreatorName` \n" +
            "FROM\n" +
            "\t`reply` AS `reply`\n" +
            "\tLEFT OUTER JOIN `ask` AS `ask` ON `reply`.`askId` = `ask`.`id`\n" +
            "\tLEFT OUTER JOIN `course` AS `ask->course` ON `ask`.`courseId` = `ask->course`.`id`\n" +
            "\tLEFT OUTER JOIN `user` AS `ask->creator` ON `ask`.`userId` = `ask->creator`.`id` ${ew.customSqlSegment}")
    public List<MyReplyBo> myreply(@Param(Constants.WRAPPER) QueryWrapper queryWrapper);
}
